package GUI;
////////////////////////////////////////////////////////////////////
//To save new assignment the File Name have to be 14 Letters 5 for course id,3 for ClassId,6 for DeadLine(2-Day,2-mounth,2-year)
// and 2 for task Num
//
//To Save a new Evaluation Form the have to be 8 letters 5 for course id,3 for StudentId
import java.awt.Dimension;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
/**
 * 
 * Teacher mainmenu frame, this frame has a menu specific to this user and his 
 * functionalities in our system
 *
 */
public class TeacherMainMenu extends JFrame {
	private JMenuBar menuBar=null;
	private JMenu mnAcademicActivity=null;
	private JMenuItem mntmCheckAssignmentWizard=null;
	private JMenuItem mntmDefineNewAssignment=null;
	private JMenuItem mntmFillEvaluationForm=null;
	private JMenu mPersonalData = null;
	private JMenuItem mntmViewPersonalData=null;
	public static Dimension defaultDim=null;
	private JMenuItem logout = null;
	public Login myLoginFrame = null;
	private JFileChooser tfc;

//making menu bar for the Teacher Window
	private JMenuBar createMenuBar()
	{
		if (menuBar==null)
		{
			menuBar = new JMenuBar();
			 mnAcademicActivity = new JMenu("Academic activity");
			  tfc = new JFileChooser();
			 mntmCheckAssignmentWizard = new JMenuItem("Check assignment wizard");
			 mntmCheckAssignmentWizard.addActionListener(new java.awt.event.ActionListener()
				{	
					public void actionPerformed(java.awt.event.ActionEvent e)
				
					{
						System.out.println("Check assignment wizard");
	
						
				
					}});
			 mntmDefineNewAssignment = new JMenuItem("Define new assignment");
			
			 mntmDefineNewAssignment.addActionListener(new java.awt.event.ActionListener()
				{	
					public void actionPerformed(java.awt.event.ActionEvent e)
				
					{
						
						int returnVal = tfc.showOpenDialog(TeacherMainMenu.this);
						if (returnVal == JFileChooser.APPROVE_OPTION){
							//Geting the File
							File sNewAssign = tfc.getSelectedFile();
							String cid= sNewAssign.getName().substring(0,5);			// 5 digit's for cours number
							String classID=sNewAssign.getName().substring(5,8);			// 3 digit's for Class Number
							String taskNum=sNewAssign.getName().substring(8,9);			// 2 digit's deadLine taskNum
							String day=sNewAssign.getName().substring(9,11);			// 2 digit's deadLine day
							String mounth=sNewAssign.getName().substring(11,13);		// 2 digit's for mounth deadLine
							String year=sNewAssign.getName().substring(13,15);			// 2 digit's for year deadLine
							String deadLine=day+":"+mounth+":"+year;
							//	String tID = myLoginFrame.userID;
							String msg="tnewtask "+deadLine+" "+classID+" "+cid+" "+taskNum+" "+sNewAssign.getAbsolutePath();
							myLoginFrame.client.handleMessageFromClientUI(msg);
						//TODO what happends when a parent clicks "mntmSubmitSolution" 
						}
						
				}
			});
			 mntmFillEvaluationForm = new JMenuItem("Fill evaluation form");
			 mntmFillEvaluationForm.addActionListener(new java.awt.event.ActionListener()
				{	
					public void actionPerformed(java.awt.event.ActionEvent e)
				
					{
						
						//getting the file from a JFILECHOOSER
						int returnVal = tfc.showOpenDialog(TeacherMainMenu.this);
						if (returnVal == JFileChooser.APPROVE_OPTION){
							//Geting the File
							File tNewevaluation = tfc.getSelectedFile();
							String classID= tNewevaluation.getName().substring(0,5);			// 5 digit's for course number
							String sid=tNewevaluation.getName().substring(5,8);					// 3 digit's for student ID
							String msg="tNewevaluation "+sid+" "+classID+" "+tNewevaluation.getAbsolutePath();
							myLoginFrame.client.handleMessageFromClientUI(msg);
					}	
						//TODO what happends when a parent clicks "mntmSubmitSolution" 
						
				}
			});
			 logout = new JMenuItem("Logout");
			  logout.addActionListener(new java.awt.event.ActionListener()
				{	
					public void actionPerformed(java.awt.event.ActionEvent e)
				
					{
						System.out.println("logout");
						if(myLoginFrame.LoginResult.equalsIgnoreCase("OK"))
						{
							myLoginFrame.client.handleMessageFromClientUI("logout "+myLoginFrame.UserName.getText().toString());
						}
						myLoginFrame.UserName.setText("");
						myLoginFrame.Password.setText("");
						myLoginFrame.setContentPane(myLoginFrame.getFirstPanel());
						myLoginFrame.setVisible(true);
						
						myLoginFrame.LoginResult=null;
						myLoginFrame.UserType=null;
						setVisible(false);
						
						
						//TODO what happends when a parent clicks "mlogout" 
						
				}
			}); 
			
		}
		
		return menuBar; 
	}
	
	
	private void initialize()
	{
		this.setSize(defaultDim=new Dimension(600,600));
		this.setTitle("Teacher main menu");
		this.setJMenuBar(createMenuBar());
		menuBar.add(mnAcademicActivity);
		mnAcademicActivity.add(mntmCheckAssignmentWizard);
		mnAcademicActivity.add(mntmDefineNewAssignment);
		mnAcademicActivity.add(mntmFillEvaluationForm);
		menuBar.add(logout);
	}
	/**
	 * Constructor for this class
	 */
	
	
	public TeacherMainMenu() {
		
		super();
		initialize();
		
	}

}
